Skip to content

Fix listing virtual machines with vnfnics - #161

Merged
abh1sar merged 2 commits into
mainfrom
fix-vnfnics
Aug 10, 2026
Merged

Fix listing virtual machines with vnfnics#161
abh1sar merged 2 commits into
mainfrom
fix-vnfnics

Conversation

@weizhouapache

Copy link
Copy Markdown
Member

This fixes #159

Copilot AI lite review requested due to automatic review settings August 5, 2026 08:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Fixes CloudStack response decoding for the vnfnics field by introducing a structured VnfNic type and updating generated response structs to use it, addressing #159.

Changes:

  • Add a hand-maintained VnfNic struct to match the (undocumented) API response shape.
  • Update vnfnics fields from []string to []*VnfNic across multiple response/resource types.
  • Update generator mapping so vnfnics is emitted as []*VnfNic.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
generate/generate.go Generates VnfNic and maps vnfnics to []*VnfNic.
cloudstack/VirtualNetworkFunctionsService.go Adds VnfNic type and updates VNF appliance responses to use it.
cloudstack/VirtualMachineService.go Updates many VM-related responses/resources to use []*VnfNic for vnfnics.
cloudstack/SnapshotService.go Updates snapshot response to use []*VnfNic for vnfnics.
cloudstack/SSHService.go Updates SSH reset response to use []*VnfNic for vnfnics.
cloudstack/NicService.go Updates NIC update response to use []*VnfNic for vnfnics.
cloudstack/ISOService.go Updates ISO attach/detach responses to use []*VnfNic for vnfnics.
cloudstack/BackupService.go Updates VM-from-backup response to use []*VnfNic for vnfnics.
cloudstack/AffinityGroupService.go Updates VM affinity group response to use []*VnfNic for vnfnics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread generate/generate.go
Comment thread generate/generate.go
Comment thread cloudstack/VirtualMachineService.go
Comment thread cloudstack/VirtualNetworkFunctionsService.go
Both list structs took their json tag from the API name, so they looked for
"vnftemplate" and "vnfappliance". Neither key exists in the server response:
ListVnfTemplatesCmd is an empty subclass of ListTemplatesCmd and returns its
items under "template", and ListVnfAppliancesCmd inherits execute() from
ListVMsCmd and returns its items under "virtualmachine". Both calls therefore
returned a correct Count with an always-empty slice, which also made
GetVnfTemplateByName/ByID and GetVnfApplianceByName/ByID always report that
the resource was not found.

Adds both to the existing switch of APIs whose response key differs from the
API name, alongside cases like listVirtualMachinesUsageHistory, and
regenerates. Verified against a 4.22.1.0 server response that returns one VNF
template: it decodes to one element instead of zero.
Copilot AI review requested due to automatic review settings August 10, 2026 14:28
@abh1sar
abh1sar marked this pull request as ready for review August 10, 2026 14:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (1)

generate/generate.go:2432

  • mapType maps any response field named vnfnics (type list) to []*VnfNic, but VnfNic is only emitted opportunistically for the listVnfAppliances API earlier in this file. This makes the generator brittle: if the API set ever includes vnfnics but not listVnfAppliances (or if services are generated/consumed selectively), the generated code will fail to compile due to an undefined VnfNic type.

Consider making VnfNic a stable, package-level type that does not depend on a single API being present (e.g., place it in a small hand-maintained file under cloudstack/, or have the generator emit it once when it first encounters a vnfnics list field).

		if pName == "vnfnics" {
			return "[]*VnfNic"
		}

@abh1sar abh1sar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM tested

@abh1sar
abh1sar merged commit 37d668c into main Aug 10, 2026
4 checks passed
@abh1sar
abh1sar deleted the fix-vnfnics branch August 10, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cannot unmarshal object into Go struct field ListVirtualMachinesResponse.virtualmachine.vnfnics of type string

3 participants